#include <iostream>
#include <string>
using namespace std;

bool prime(int n) {
    if (n%2 == 0) {
        return false;
    }
    for (int i = 2; i <= n/2 + 1; i++) {
        if (n%i == 0) {
            return false;
        }
    }
    return true;
}

int ans(int n, string temp) {
    if (temp != "") {
        return -1;
    }
    else {
        int maxn = n;
        int minn = n;
        if (prime(n)) {
            return n;
        }
        else {
            while (true) {
                if (prime(minn)) {
                    return minn;
                }
                else if (prime(maxn)) {
                    return maxn;
                }
                else {
                    maxn++;
                    minn--;
                }
            }
        }
    }
}

int main() {
    string num;
    getline(cin, num);
    string nums[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int b = 0;
    int number = 0;
    int le = num.length();
    string temp = "";
    for (int i = 0; i < le; i++) {
        if (num[i] != ' ') {
            temp += num[i];
            b++;
        } else {
            for (int j = 0; j < 10; j++) {
                if (temp == nums[j]) {
                    number = number*10 + j;
                    temp = "";
                    b == 0;
                    break;
                }
            }
        }
    }
    
    if (!temp.empty()) {
        for (int j = 0; j < 10; j++) {
            if (temp == nums[j]) {
                number = number*10 + j;
                temp ="";
                break;
            }
        }
    }
    if(ans(number, temp) == -1){
        cout << "Wrong input" << endl;
    }
    else{
        cout << ans(number, temp) << endl;
    }
    
    return 0;
}